home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 February / PCpro_2005_02.ISO / files / opensource / A_Note_4.2.1 / setup.exe / {app} / Server Documents / savenotes.php < prev    next >
Encoding:
PHP Script  |  2004-10-01  |  3.6 KB  |  115 lines

  1. <?php
  2. // Save the notes in the database
  3.  
  4. function get_string($h, $s, $e)
  5. {
  6. // Check that the start tag is NOT the same as the end tag
  7. if ($s == $e)
  8.    return "";
  9.  
  10. // Check that the start tag exists
  11. if (strpos ($h, $s, 0) === false)
  12.    return "";
  13.  
  14. // Check that the end tag exists
  15. if (strpos ($h, $e, 0) === false)
  16.    return "";
  17.  
  18. $sp = strpos($h, $s, 0) + strlen($s);  
  19. $ep = strpos($h, $e, 0); 
  20.  
  21. // Check that the start tag comes before the end tag
  22. if ($sp >= $ep)
  23.    return "";
  24.  
  25. return substr($h, $sp, $ep-$sp);
  26. }
  27.  
  28. // Erase every note
  29. $query = "DELETE FROM note WHERE userid=$userid";
  30. $reply = mysql_query ($query);
  31. if ($reply === 0)    {
  32.     echo $xmlstart ."<info info=\"The notes couldn't be deleted\"/>";
  33.     exit;
  34. }
  35. // Get the xml
  36. $data = $HTTP_RAW_POST_DATA;
  37.  
  38.  
  39. // Find the note and save it
  40. while ($data != "")    {
  41.     $start = '<note>';
  42.     $end = '</note>';
  43.     $found = get_string($data, $start, $end);
  44.  
  45.     if ($found === "")
  46.         break;
  47.         
  48. // Get the data
  49.     $noteversion    = get_string ($found, "<noteversion>", "</noteversion>");
  50.     $noteid            = get_string ($found, "<noteid>", "</noteid>");
  51.     $alarmtime        = get_string ($found, "<alarmtime>", "</alarmtime>");    
  52.     $usealarm        = get_string ($found, "<usealarm>", "</usealarm>");    
  53.     $title            = get_string ($found, "<title>", "</title>");    
  54.     $visible        = get_string ($found, "<visible>", "</visible>");    
  55.     $notecolor        = get_string ($found, "<notecolor>", "</notecolor>");    
  56.     $positionleft    = get_string ($found, "<positionleft>", "</positionleft>");    
  57.     $positiontop    = get_string ($found, "<positiontop>", "</positiontop>");
  58.     $width            = get_string ($found, "<width>", "</width>");
  59.     $height            = get_string ($found, "<height>", "</height>");
  60.     $text            = get_string ($found, "<text>", "</text>");
  61.     $dockedleft        = get_string ($found, "<dockedleft>", "</dockedleft>");    
  62.     $dockedtop        = get_string ($found, "<dockedtop>", "</dockedtop>");    
  63.     $dockedright    = get_string ($found, "<dockedright>", "</dockedright>");    
  64.     $dockedbottom    = get_string ($found, "<dockedbottom>", "</dockedbottom>");                
  65.  
  66.     $slidedleft        = get_string ($found, "<slided-left>", "</slided-left>");                
  67.     $slidedright    = get_string ($found, "<slided-right>", "</slided-right>");                
  68.     $slidepositionleft = get_string ($found, "<slidepositionleft>", "</slidepositionleft>");                
  69.     $slidepositiontop     = get_string ($found, "<slidepositiontop>", "</slidepositiontop>");                
  70.     $slidepositionright = get_string ($found, "<slidepositionright>", "</slidepositionright>");                
  71.     $slidepositionbottom = get_string ($found, "<slidepositionbottom>", "</slidepositionbottom>");                
  72.                         
  73. // Save the note
  74.     $query = "INSERT INTO note values (        \"$userid\", 
  75.                                             \"$noteid\", 
  76.                                             \"$noteversion\", 
  77.                                             \"$text\",
  78.                                             \"$alarmtime\",
  79.                                             \"$usealarm\",
  80.                                             \"$title\",
  81.                                             \"$visible\",
  82.                                             \"$notecolor\",
  83.                                             \"$positionleft\",
  84.                                             \"$positiontop\",
  85.                                             \"$width\",
  86.                                             \"$height\",
  87.                                             \"$dockedleft\",
  88.                                             \"$dockedtop\",
  89.                                             \"$dockedright\",
  90.                                             \"$dockedbottom\",
  91.                                             \"$slidedleft\",
  92.                                             \"$slidedright\",
  93.                                             \"$slidepositionleft\",
  94.                                             \"$slidepositiontop\",
  95.                                             \"$slidepositionright\",
  96.                                             \"$slidepositionbottom \"    
  97.                                             )";
  98.     $reply = mysql_query ($query);
  99.  
  100. // Something went wrong
  101.     if ($reply === 0)    {
  102.         echo $xmlstart ."<info info=\"The note couldn't be inserted\"/>";
  103.         exit;
  104.     }
  105.  
  106. // Jump over one <note>...</note>
  107.     $a = strpos ($data, $end) + strlen ($end);
  108.     $data = substr ($data, $a);
  109. }
  110.  
  111. // Everytning is ok
  112. echo $xmlstart ."<info info=\"The notes was uploaded\"/>";
  113.  
  114. ?>
  115.